<?

if ($c = stack('name')) {

	$_id_component	= $DATA['components'][$c]['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value
	$_lang			= context('lang');

	$_crit = "id_data=$_id_data AND id_parent=$_id_component AND attr & ".AA_VISIBLE;


	$s = array_extend( array(
		'path' => 'project', 'w' => 128, 'h' => 96, 'param' => 'id', 'sw' => 640, 'sh' => 390
	), component_settings($c));
	
	$dx = array('rows' => $_num_rows, 'cols' => $_num_cols);




	$a = param($s['param']);

	if ( $temp = datafetch('db_item', tb('data'), "$_crit AND id=$a")) {

		$dx['object'] = array_merge($temp, datafetch_array('meta', $_id_meta, $a, $CONTEXT['lang']));
		
		$_cr2 = "id_data=$_id_data AND id_parent=$a AND attr & ".AA_VISIBLE;

		$dx['objects'] = datafetch_array('db_list', array('table' => tb('data'), 'where' => $_cr2, 'order' => 'id_index', 'index' => 'id' ));

		$dx['meta'] = datafetch_array('db_list', array(
			'table' => tb('data'), 
			'where' => "id_data=$_id_meta AND id_parent in (".implode(',', array_keys($dx['objects'])).')',	
			'index' => 'id', 
		));
		
		foreach($dx['meta'] as $k => $v) {
			if ($v['assoc'])
				$dx['objects'][$v['id_parent']]['meta'][$v['name']][$v['assoc']] = $v['value'];
			else
				$dx['objects'][$v['id_parent']][$v['name']] = $v['value'];
		}
	
		foreach($dx['objects'] as $k => $v) {
	
			if (isset($v['meta'])) 	// parse language dependent data
				foreach($v['meta'] as $mname => $mv) {
					if ($mv[$_lang] && ($mv[$_lang] != -1))
						$dx['objects'][$k][$mname] = $mv[$_lang];
					else {	// no data in current language, get any other we can find
						foreach($DATA['langs'] as $lid => $lv) {
							if ($mv[$lid] && ($mv[$lid] != -1)) {
								$dx['objects'][$k][$mname] = $mv[$lid];
								break;
							}
						}
					}
				}

			if ($v['kind'] == 1)
				$dx['objects'][$k]['image'] = checkImage(FP_UPLOAD_PATH."$s[path]/$a/", $k);
		}

		// fix crumbs
		$temp = end(array_keys($DATA['crumb']));
		$DATA['crumb'][$temp] = array('name' => str_cut_long($dx['object']['title'], 30, '...'), 'last' => 1);
		
		$DATA['components'][$c]['data'] = $dx;
		
	} else {
		
		header("HTTP/1.0 404 Not Found\n");
		header("Location: "._transformURL($CURRENT->url, array('remove_param' => $s['param'])));
	}

	unstack();
}

?>